
from lib.api import *
import re
from lib.urls import *


def suite_setup():
    INFO('返回token')
    global auth_token
    auth_token = am.getToken()




class API_3001:
    name = 'API_3001'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[14][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))





class API_3002:
    name = 'API_3002'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token过期，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))



class API_3003:
    name = 'API_3003'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token 为空，'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'正确")
        urlpara = {
            'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 # headers={
                                 #     "auth-token": 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlS2V5IjoiIiwidXNlck5hbWUiOiJ5enlhZG1pbiIsImV4cCI6MTYyMTkzNzIwNCwidXNlcklkIjoieXp5YWRtaW4ifQ.xVITR8Cn0zLrJSA3tKMt48bTyk6tFhlRwjIp4e_yFys'
                                 # },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))



class API_3004:
    name = 'API_3004'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，'pointName':'ZGZ.PSD.CONTROL.ddocb_0'错误，PSD的控点存在，但不在目标控点内")
        urlpara = {
            'pointName':'ZGZ.PSD.CONTROL.ddocb_0'
        }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 },
                                 params=urlpara
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))


class API_3005:
    name = 'API_3005'       # 测试用例名字
    def teststeps(self):

        INFO('控制接口：电扶梯控制接口 测试     #3.1')
        INFO("前置条件：token正确，'pointName'不填")
        # urlpara = {
        #     'pointName':'ZGZ.BAS.ZM.CONTROL.ddocb01_0'
        # }
        response = requests.post(url_Target_Address+url_Control_ESCControl,
                                 headers={
                                     "auth-token": auth_token
                                 }
                                 )
        expectedResult = json.dumps(json.loads(am.expectedResult()[15][3]), ensure_ascii=False, indent=4)
        outExpectedResult = '预期结果:\n' + expectedResult
        INFO(outExpectedResult)
        am.printResponse(response)
        result = sorted(set(re.sub('\\s|{|}|\\[|]','',expectedResult).split(',')) ^ set(re.sub('\\s|{|}|\\[|]','',response.content.decode('utf8')).split(',')))          #对比两个字符串中的不同并打印
        INFO('\n对比结果：\n'+str(result))
        CHECK_POINT('预期结果和输出结果是否保持一致',expectedResult==response.content.decode('utf8'))




